#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
long long qexp(ll a, ll b, ll m) {
  long long res = 1;
  while(b) {
    if(b&1)res = res*a%m;
    a = a*a%m;
    b>>=1;
  }
  return res;
}
int main() {
  int tc;cin>>tc;
  while(tc--) {
    long long a, b, m=1e9+7;
    cin>>a>>b;
    cout<<qexp(a,b,m)<<'\n';
  }
}
